package com.xplay.xpocker.norm;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 *
 */
public abstract class AbstractStrategy<T, R> {
    protected final Type[] getTR() {
        Class<T> result = null;
        Type type = getClass().getGenericSuperclass();
        if (type instanceof ParameterizedType) {
            ParameterizedType parameterizedType = (ParameterizedType) type;
            Type[] typeArguments = parameterizedType.getActualTypeArguments();
            if (typeArguments.length < 2) {
                throw new RuntimeException("Please pass generic parameters");
            }
            return typeArguments;
        }
        throw new RuntimeException("Please pass generic parameters");
    }


    protected final Class<T> getFirst() {
        return (Class<T>) (getTR()[0]);
    }

    protected final Class<R> getLast() {
        return (Class<R>) (getTR()[1]);
    }
}
